<template>
  <div class="attention_view">
    <van-tabs v-model="active" duration="0">
      <van-tab title="用户">
        <van-list
          v-model="loading"
          :finished="finished"
          finished-text="没有更多了"
          @load="onLoad"
        >
          <div class="item" v-for="(item, index) in list" :key="index">
            <van-image
              @click="goAnchorView(index)"
              width="38"
              height="38"
              :src="item.img"
            />
            <div class="font" @click="goAnchorView(index)">
              <div class="brief">
                <h6>{{ item.name }}</h6>
                <p>{{ item.character }}</p>
              </div>
              <button @click="attentionChange(index)">
                {{ item.follow ? "未关注" : "已关注" }}
              </button>
            </div>
          </div>
        </van-list>
        <div class="prompt" :class="{ prompt_con: !listIs }" v-if="!listIs">
          <van-image
            width="257"
            height="128"
            src="/img/collect/loadingA.jpg"
            alt="loading"
          />
          <p>你还没有关注任何人哦～</p>
        </div>
      </van-tab>
      <van-tab title="店铺">
        <div class="prompt">
          <van-image
            width="257"
            height="128"
            src="/img/collect/loadingA.jpg"
            alt="loading"
          />
          <p>你还没有关注任何店铺哦～</p>
        </div>
      </van-tab>
    </van-tabs>
  </div>
</template>

<script>
import { mapState, mapMutations } from "vuex";

export default {
  data() {
    return {
      active: 0,
      list: [],
      loading: false,
      finished: false,
    };
  },

  mounted() {},

  methods: {
    onLoad() {
      // 异步更新数据
      // setTimeout 仅做示例，真实场景中一般为 ajax 请求
      setTimeout(() => {
        let date = this.date.filter((item) => !item.follow);
        for (let i = 0; i < date.length; i++) {
          this.list.push(date[i]);
        }
        // 加载状态结束
        this.loading = false;
        // 数据全部加载完成
        if (this.list.length >= date.length - 1) {
          this.finished = true;
        }
      }, 1000);
    },
    ...mapMutations(["attentionChange"]),
    goAnchorView(i) {
      this.$router.push({
        name: "anchor",
        params: {
          actorIdUrl: this.date[i].actorIdUrl,
          name: this.date[i].name,
          img: this.date[i].img,
          follow: this.date[i].follow,
          index: i,
          character: this.date[i].character,
          num: this.date[i].num,
        },
      });
    },
  },
  computed: {
    ...mapState(["date"]),
    listIs() {
      return this.list.length == 0 ? false : true;
    },
  },
};
</script>

<style lang="scss" scoped>
* {
  padding: 0;
  margin: 0;
}
.attention_view {
  background-color: #fff;
}
.item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  height: 59px;
  .font {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 85.2%;
    height: 100%;
    border-bottom: 1px solid #e5e5e5;
  }
  .brief {
    width: 73.6%;
    h6 {
      width: 100%;
      height: 22px;
      line-height: 22px;
      font-size: 14px;
      color: #333;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    p {
      width: 100%;
      height: 20px;
      line-height: 20px;
      font-size: 12px;
      color: #999;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
  }
  button {
    width: 60px;
    height: 28px;
    border-radius: 12px;
    border: 1px solid #9a9a9a;
    background-color: #fff;
    font-size: 12px;
    color: #999;
  }
}
.prompt {
  height: 400px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background-color: #fff;
  &.prompt_con {
    position: relative;
    bottom: 50px;
  }
  p {
    font-size: 16px;
    color: #666;
    margin-top: 15px;
  }
}
::v-deep .van-image {
  border-radius: 50%;
  overflow: hidden;
}
::v-deep .van-tab__text {
  font-size: 15px;
}
::v-deep .van-tabs__line {
  width: 8.7%;
  height: 2px;
  bottom: 22px;
}
::v-deep .van-tab--active {
  color: #ff55a3;
}
::v-deep .van-tabs__wrap {
  padding: 0 15px;
  align-items: center;
  border-bottom: 1px solid #e5e5e5;
}
</style>